package com.magicode.cms.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.magicode.cms.common.assist.UtilPath;
import com.magicode.cms.dao.IFeesStandardDao;
import com.magicode.cms.entiy.base.FeesStandard;
import com.magicode.cms.entiy.base.NewsComment;
import com.magicode.cms.service.IFeesStandardService;

@Service("feesStandardService")
public class FeesStandardServiceImpl extends BaseServiceImpl<FeesStandard,IFeesStandardDao> implements IFeesStandardService{

	@Autowired
	@Qualifier("daofeesStandard")
	private IFeesStandardDao feesStandardDao;

	public IFeesStandardDao getFeesStandardDao() {
		return feesStandardDao;
	}

	public void setFeesStandardDao(IFeesStandardDao feesStandardDao) {
		this.feesStandardDao = feesStandardDao;
	}

	@Override
	public List<Map<String, Object>> getBeanInfo() {
		List<Map<String, Object>> beaninfo = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(json_key, "title");
		map.put(json_title, "标题");
		map.put("width", 100);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "code");
		map.put(json_title, "编码");
		map.put("width", 100);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "type");
		map.put(json_title, "类型");
		map.put("width", 100);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "originalCoinCount");
		map.put(json_title, "原价");
		map.put("width", 80);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "currentCoinCount");
		map.put(json_title, "现价");
		map.put("width", 80);
		beaninfo.add(map);
		map = new HashMap<String, Object>();
		map.put(json_key, "remark");
		map.put(json_title, "描述");
		map.put("width", 180);
		beaninfo.add(map);
		return beaninfo;
	}

	@Override
	public String getHql(Map<String, String> querywhere) throws Exception {
		String hql =" from "+FeesStandard.class.getName()+" "+entity_alias_name+" ";
		hql += " left join "+entity_alias_name+".type as ty ";
		if(!querywhere.isEmpty()){
			hql += "where 1 = 1 ";
			if(querywhere.containsKey("title")){
				hql = hql+" and "+entity_alias_name+".title like '%"+querywhere.get("title")+"%'";
			}
			if(querywhere.containsKey("dicTypeid")){
				hql = hql+" and "+entity_alias_name+".type.id='"+querywhere.get("dicTypeid")+"'";
			}
		}
		return hql;
	}

	@Override
	public List<Map<String, Object>> grid(Map<String, String> querywhere) {
		List<Map<String, Object>> resultList = null;
		try {
			Integer start = this.getGridStartOrSize(querywhere, 0, field_grid_start);
			Integer size = this.getGridStartOrSize(querywhere, 20, field_grid_size);
			String hql = this.getHql(querywhere);
			Map<String,String> gridsel = new HashMap<String,String>();
			gridsel.put(field_id, ""+entity_alias_name+".id as id ");
			gridsel.put(field_title, ""+entity_alias_name+".title as title");
			gridsel.put("code", ""+entity_alias_name+".code as code");
			gridsel.put("type", "ty.title as type");
			gridsel.put("originalCoinCount", ""+entity_alias_name+".originalCoinCount as originalCoinCount");
			gridsel.put("currentCoinCount", ""+entity_alias_name+".currentCoinCount as currentCoinCount");
			gridsel.put("remark", ""+entity_alias_name+".remark as remark");
			resultList = this.queryMapDataList(hql, gridsel, start, size);
			return resultList;
		} catch (Exception e) {
			return new ArrayList<Map<String, Object>>();
		}
	}

	@Override
	public IFeesStandardDao getDao() throws Exception {
		// TODO Auto-generated method stub
		return feesStandardDao;
	}
}
	